// Checks for valid and unique username
$(document).ready(function() {
						
	// check for CAPSLOCK and show notice if pressed
	$(window).keypress(function(e) {
								
		var s = String.fromCharCode(e.keyCode);
		
		if(s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey) {
			
			alert('Please turn off Caps Lock');
			
		}
								
	});
	
	// check that dob is at least 13 years ago
	/*$("#dob_y").change(function() {
		
		var userDOB = $("#dob_y").val() + '-' + $("#dob_m").val() + '-' + $("#dob_d").val();
		
		$("#date_status").html('<img src="chrome/spinner.gif" /> Checking Date&hellip;');
		
		$.ajax({
			   
			type: "POST",
			url: "include/date_check.php",
			data: "date=" + userDOB,
			success: function(msg) {
				
				$("#date_status").ajaxComplete(function(event, request, settings) {
					
					$(this).html(msg);
				
				});
				
			}
			   
		});
		
	});*/
	
	// check for availability of username
	$("#username").keyup(function() {
	
		var usr = $("#username").val();
		
		if(usr.length >= 3) {
		
			$("#user_status").html('<img src="chrome/spinner.gif" /> Checking Availability&hellip;');
			
			$.ajax({
				type: "POST",
				url: "include/user_check.php",
				data: "username=" + usr,
				success: function(msg) {
				
					$("#user_status").ajaxComplete(function(event, request, settings) {
					
						if(msg == 'OK') {
						
							$(this).html('<img src="chrome/accept.png" /> <span class="success">Available!</span>');
						
						}else{
						
							$(this).html(msg);
						
						}
					
					});
					
				}
				
			});
		
		}
	
	});
	
	// check that passwords match
	$("#pass_check").keyup(function() {
								   
		var pass = $("#password").val();
		var check = $("#pass_check").val();
		
		$("#pass_status").html('<img src="chrome/spinner.gif" /> Checking&hellip;');
		
		if(pass == check) {
				
			$("#pass_status").html('<img src="chrome/accept.png" /> <span class="success">Matched!</span>');
			
		}else{
			
			$("#pass_status").html('<img src="chrome/error.png" /> <span class="error">Passwords don\'t match!</span>');
			
		}
											   
	});

});